import cv2
import numpy as np
from time import time

img = cv2.imread("./img/culture1.png")
# 新建一个与img同等大小，但通道数为一的图 （灰度图）
tmp = np.zeros(img.shape[:2])
h, w, c = img.shape
img = img / 255.  # 将图像中的每一个像素点的值，取值到0~1之间

start = time()

# 耗时：6.348126173019409
# for i in range(h):
#     for j in range(w):
#         # 加权平均
#         tmp[i][j] = img[i][j][0] * 0.6 + img[i][j][1] * 0.3 + img[i][j][2] * 0.1

# 耗时：0.07758665084838867
tmp = img[:, :, 0] * 0.6 + img[:, :, 1] * 0.3 + img[:, :, 2] * 0.1

end = time()
print(end - start)

tmp = tmp * 255
tmp = tmp.astype(np.uint8)
cv2.imshow("tmp", tmp)
cv2.waitKey(0)
